using System;
using System.Collections;
using System.Globalization;
using System.Windows.Data;
using WPFTemplateLib.WpfConverters.Core;

namespace WPFTemplateLib.WpfConverters
{
	/// <summary>
	/// [转换器] 通过参数字符串键查找字典中的值
	/// </summary>
	[Obsolete("好像达不到预期效果")]
	public class BindDictFindValueByParaStrKeyConverter : ValueConverterBase
	{
		/// <summary>
		/// 未找到时返回的值
		/// </summary>
		public object NotFoundReturnValue { get; set; }

		/// <inheritdoc />
		public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			string key = parameter + "";
			if(value is not IDictionary dict || string.IsNullOrWhiteSpace(key))
			{
				return Binding.DoNothing;
			}

			if(dict.Contains(key))
			{
				return dict[key];
			}
			else
			{
				return NotFoundReturnValue ?? Binding.DoNothing;
			}
		}
	}
}
